package com.xqls.controller;

import com.xqls.biz.*;
import com.xqls.util.CommonPage;
import com.xqls.util.CommonResult;
import com.xqls.util.DictionaryEnums;
import com.xqls.util.GetKeyByValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by hdg on 2017/7/14.
 */
@Controller
@RequestMapping(value = "/realdatarecord")
public class RealdataRecordController {
    @Autowired
    private RainwaterDischargeRealdataRecordBiz rainwaterBiz;
    @Autowired
    private PublicStormwaterRealdataRecordBiz publicBiz;
    @Autowired
    private DischargeRealdataRecordBiz discharBiz;
    @Autowired
    private IntakeRealdataRecordBiz intakeBiz;
    @Autowired private FluggasDischargeRealdataRecordBiz fluggasBiz;

    @Autowired private DictionaryBiz dictionaryBiz;

    @RequestMapping(value = "/{tablename}/realdatarecordList")
    public ModelAndView realdataList(@PathVariable(value = "tablename") String tablename) {
        ModelAndView view = new ModelAndView("RealdataRecord/realdatarecordList");
        String url = null;
        String title = null;
        Map<Integer, String> map = dictionaryBiz.queryDictionaryByParent(  DictionaryEnums.COMPANY_TYPE.getCode());
        if (tablename.equals("intake")) {
            url = "/realdatarecord/IntakeListDataRecord";
            title = "取水口实时数据历史记录";
            view.addObject("deviceType", GetKeyByValue.getKey(map, "取水口"));
            view.addObject("count",intakeBiz.queryAll());
        } else if (tablename.equals("discharge")) {
            url = "/realdatarecord/DischargelistDataRecord";
            title = "排放口实时数据历史记录";
            view.addObject("deviceType", GetKeyByValue.getKey(map, "排放口"));
            view.addObject("count",discharBiz.queryAll());
        } else if (tablename.equals("rainwater")) {
            url = "/realdatarecord/RainwaterDischargeRealdataRecord";
            title = "企业雨水排放口实时数据历史记录";
            view.addObject("deviceType", GetKeyByValue.getKey(map, "企业雨水排放口"));
            view.addObject("count",rainwaterBiz.queryAll());
        } else if (tablename.equals("stormwater")) {
            url = "/realdatarecord/PublicStormwaterRealdataRecord";
            title = "公共雨水排放口实时数据历史记录";
            view.addObject("deviceType", GetKeyByValue.getKey(map, "公共雨水排放口"));
            view.addObject("count",publicBiz.queryAll());
        }
        else if (tablename.equals("fluggas")) {
            url = "/realdatarecord/FluggasDischargeRealdataRecord";
            title = "废气排放口实时数据历史记录";
            view.addObject("deviceType", GetKeyByValue.getKey(map, "废气排放口"));
            view.addObject("count",fluggasBiz.queryAll());
        }
        view.addObject("columns", CommonPage.setColumnToPage(null,
                null, url, title));
        view.addObject("tablename",tablename);
        return view;
    }

    @RequestMapping("/IntakeListDataRecord")
    @ResponseBody
    public CommonResult intakeListData(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
        CommonResult commonResult = intakeBiz.queryIntakeRealdataRecord(commonPage,request,response);//完成
        if (commonResult.getIsSuccess()) {
            commonResult.setData(commonPage);
        }

        return commonResult;
    }

    @RequestMapping("/DischargelistDataRecord")
    @ResponseBody
    public CommonResult discharListData(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
        CommonResult commonResult = discharBiz.queryDischargeRealdataRecord(commonPage,request,response);
        if (commonResult.getIsSuccess()) {
            commonResult.setData(commonPage);

        }

        return commonResult;
    }

    @RequestMapping("/PublicStormwaterRealdataRecord")
    @ResponseBody
    public CommonResult PublicStormwaterRealdata(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
        CommonResult commonResult = publicBiz.queryPublicStormwaterRealdataRecord(commonPage,request,response);
        if (commonResult.getIsSuccess()) {
            commonResult.setData(commonPage);

        }

        return commonResult;
    }

    @RequestMapping("/RainwaterDischargeRealdataRecord")
    @ResponseBody
    public CommonResult RainwaterDischargeRealdata(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
        CommonResult commonResult = rainwaterBiz.queryRainwaterDischargeRealdataRecord(commonPage,request,response);
        if (commonResult.getIsSuccess()) {
            commonResult.setData(commonPage);

        }

        return commonResult;
    }

    @RequestMapping("/FluggasDischargeRealdataRecord")
    @ResponseBody
    public CommonResult FluggasDischargeRealdata(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response) {
        CommonResult commonResult = this.fluggasBiz.queryFluggasDischargeRealdataRecord(commonPage,request,response);
        if (commonResult.getIsSuccess()) {
            commonResult.setData(commonPage);
        }
        return commonResult;
    }
}
